exports.scrollTop = function () {
    setTimeout(function () {
        (function scrollTop() {
            var currentScroll = document.documentElement.scrollTop || document.body.scrollTop;
            if (currentScroll > 0) {
                window.requestAnimationFrame(scrollTop);
                window.scrollTo(0, currentScroll - (currentScroll / 5));
            }
        })();
    }, 0)
};
exports.exportExcel = function (opt, name) {
    var a = document.createElement('a');
    var data_type = 'data:application/vnd.ms-excel';
    var table_div = document.getElementById(opt);
    var table_html = table_div.outerHTML.replace(/ /g, '%20');
    a.href = data_type + ', ' + table_html;
    a.download = name + '.xls';
    a.click();
};
exports.get_depart = function (callback) {
    var session = $$.sessionStore('dpt');
    if (session) {
        session.children[0].state = {selected: false};
        $$.m.depart = session;
        $$.m.dpt_id = session.selected;
        callback(callback);
    }
    else {
        var opt = {
            url: "/sys/dpt/lists",
            result: {
                $200: function (ret) {
                    ret.data.state.selected = false;
                    ret.data.selected = ret.data.children[0].id;
                    ret.data.children[0].state = {selected: true, opened: true};
                    $$.sessionStore('dpt', ret.data);
                    $$.m.depart = ret.data;
                    $$.m.dpt_id = ret.data.children[0].id;
                    $$.m.dpt_name = ret.data.children[0].text;
                    callback(callback);
                }
            }
        };
        $$.ajax(opt)
    }
};
exports.get_list = function (url, para) {
    var opts = {
        url: url,
        data: {
            page: $$.c.query.page
        },
        result: {
            $200: function (ret) {
                $$.m.data = ret.data;
                $$.toast.hide();
            },
            $400: function (ret) {
                $$.alertTips(ret.msg, 'error');
            }
        }
    };
    $.extend(opts.data, para);
    $$.ajax(opts)
};
exports.get_detail = function (url, para) {
    var opts = {
        url: url,
        data: {
            id: $$.c.query.access
        },
        result: {
            $200: function (ret) {
                $$.m.data = ret.data;
                $$.toast.hide();
            },
            $400: function (data) {
                $$.m.error = data.msg;
            }
        }
    };
    $.extend(opts.data, para);
    $$.ajax(opts)
};
